package ch.ms.persistenttimers;

/*
 * Copyright 2011 dunhill

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

import ch.ms.persistenttimers.PersistentTimer.PersistentTimerData;

/**
 * The Timer Manager controls Timers.
 * <br>
 * It also is responsible for register and unregister the timers in the system and to store and remove the timers
 * from the timer persistence part.<br/>
 * this is achieved with automatically added timer actions like OnTimerFinishAction and PersistTimerAction.
 * @author dunhill
 *
 */
public interface IPersistentTimerManager {

	/**
	 * Create a new Endless Timer. This timer will also be registered and persisted automatically!
	 * @param delay
	 * @param forceTicks
	 * @param onStartActions
	 * @param onTickActions
	 * @param onFinishActions
	 * @return
	 */
	public abstract PersistentTimer createNewEndlessTimer(float delay, boolean forceTicks);
	
	public abstract PersistentTimer createNewEndlessTimer(float delay, boolean forceTicks, String uniqueName) throws NameAlreadyTakenException;

	/**
	 * Create a new ticking timer. This timer will also be registered and persisted automatically!
	 * @param delay
	 * @param ticks
	 * @param forceTicks
	 * @param onStartActions
	 * @param onTickActions
	 * @param onFinishActions
	 * @return
	 */
	public abstract PersistentTimer createNewTickingTimer(float delay, long ticks, boolean forceTicks);
	
	public abstract PersistentTimer createNewTickingTimer(float delay, long ticks, boolean forceTicks, String uniqueName) throws NameAlreadyTakenException;

	/**
	 *  this is called, when there could be a need to recreate
	 *	the timers from internal memory. However, if this is called
	 *	during a wakeup call, nothing happens because the timers
	 *	would still be in memory and therefore its not needed to
	 *	recreate them
	 */
	public abstract void recreateTimers();

	/**
	 * Remove a timer. This will also unregister and remove the timer from the system and storage. <br/>
	 * Normally you dont need to call this, as the timer manager handles this for you.
	 * @param timer
	 */
	public abstract void removeTimer(PersistentTimer timer);
	
	public void saveTimer(PersistentTimer timer);
	
	public PersistentTimerData loadTimerData(long id);

}